package Man.glass.mgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import Man.glass.dao.AppManagerDao;
import Man.glass.entity.glass;
import Man.glass.entity.manager;
import Man.glass.entity.user;

public class AppManagerMgr {
	
	private AppManagerDao AMD = new AppManagerDao();
	
	public List<manager> queryManager(){
		return AMD.queryManager();
	}
	
	public List<user> queryUser(){
		return AMD.queryUser();
	}
	
	public boolean addUser(user u){
		return AMD.addUser(u);
	}
	
	public List<glass> queryGlass(Map<String, String> condition){
		List<glass> glassList = AMD.queryGlass();
		
		if(condition.containsKey("Name")){
			List<glass> removeGlassList =new ArrayList<glass>();
			for(glass g : glassList){
				if(!g.getName().toLowerCase().contains(condition.get("Name").toLowerCase())){
					removeGlassList.add(g);
				}
			}
			glassList.removeAll(removeGlassList);
		}
		
		if(condition.containsKey("Model")){
			List<glass> removeGlassList =new ArrayList<glass>();
			for(glass g : glassList){
				if(!g.getModel().toLowerCase().contains(condition.get("Model").toLowerCase())){
					removeGlassList.add(g);
				}
			}
			glassList.removeAll(removeGlassList);
		}
		
		if(condition.containsKey("UserCrowd")){
			List<glass> removeGlassList =new ArrayList<glass>();
			for(glass g : glassList){
				if(!g.getUseCrowd().toLowerCase().contains(condition.get("UserCrowd").toLowerCase())){
					removeGlassList.add(g);
				}
			}
			glassList.removeAll(removeGlassList);
		}
		
		if(condition.containsKey("Category")){
			List<glass> removeGlassList =new ArrayList<glass>();
			for(glass g : glassList){
				if(!g.getCategory().toLowerCase().contains(condition.get("Category").toLowerCase())){
					removeGlassList.add(g);
				}
			}
			glassList.removeAll(removeGlassList);
		}
		return glassList;
	}
}
